package com.java.example.ui.activity

import android.os.Bundle
import android.view.KeyEvent
import com.java.example.app.Constant
import com.java.example.R
import com.java.example.base.BaseActivity
import com.java.example.databinding.ActivityPolicyBinding

class PolicyActivity : BaseActivity<ActivityPolicyBinding>(R.layout.activity_policy) {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding.webview.loadUrl(Constant.USER_POLICY)
        binding.ivBack.setOnClickListener {
            if (binding.webview.canGoBack()) {
                binding.webview.goBack()
            } else {
                finish()
            }
        }
    }

    override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.repeatCount == 0) {
            if (binding.webview.canGoBack()) {
                binding.webview.goBack()
            } else {
                finish()
            }
        }
        return true
    }

    override fun onDestroy() {
        binding.webview.destroy()
        super.onDestroy()
    }

}
